
package com.cptravel.activity;

import java.util.ArrayList;
import java.util.List;

import android.support.v4.app.Fragment;
import android.view.KeyEvent;
import android.view.View;
import android.widget.RadioGroup;
import android.widget.Toast;

import com.core.util.B5MAppManager;
import com.cptravel.R;
import com.cptravel.activity.explore.ExploreFragment;
import com.cptravel.activity.hot.HotFragment;
import com.cptravel.activity.index.IndexFragment;
import com.cptravel.activity.order.OrderFragment;
import com.cptravel.view.slidingmenu.SlidingFragmentActivity;
import com.cptravel.view.slidingmenu.SlidingMenu;

public class HomeActivity extends SlidingFragmentActivity
{
    public RadioGroup rgs;
    public List<Fragment> fragments = new ArrayList<Fragment>();
    public SlidingMenu slidingMenu;

    @Override
    protected String getHeadTitle()
    {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public boolean isNoTitle()
    {
        // TODO Auto-generated method stub
        return true;
    }

    @Override
    public int doGetContentViewId()
    {
        // TODO Auto-generated method stub
        return R.layout.home;
    }

    @Override
    public void doInitSubViews(View containerView)
    {
        // TODO Auto-generated method stub
        setBehindContentView(R.layout.home_main_left);
        slidingMenu = getSlidingMenu();
        slidingMenu.setMode(SlidingMenu.LEFT_RIGHT);
        slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
        slidingMenu.setSecondaryMenu(R.layout.home_main_right);
        slidingMenu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
        slidingMenu.setFadeDegree(0.35f);
        slidingMenu.setFadeEnabled(true);
        slidingMenu.setSlidingEnabled(false);
        fragments.add(new IndexFragment());
        fragments.add(new HotFragment());
        fragments.add(new ExploreFragment());
        fragments.add(new OrderFragment());
        rgs = (RadioGroup) findViewById(R.id.tabs_rg);
        FragmentTabAdapter tabAdapter = new FragmentTabAdapter(this, fragments, R.id.tab_content, rgs);
        tabAdapter.setOnRgsExtraCheckedChangedListener(new FragmentTabAdapter.OnRgsExtraCheckedChangedListener()
        {
            @Override
            public void OnRgsExtraCheckedChanged(RadioGroup radioGroup , int checkedId , int index)
            {
                System.out.println("Extra---- " + index + " checked!!! ");
                switch (index)
                {
                    case 0:
                        break;
                    case 1:
                        break;
                    case 2:
                        break;
                    case 3:
                        break;
                }
            }
        });
    }

    @Override
    public void doInitDataes()
    {
        //        Frontia.init(getApplicationContext(), Constants.BAIDUMAP_KEY);
    }

    @Override
    public void doAfter()
    {
    }
    private long exitTime = 0;

    @Override
    public boolean onKeyDown(int keyCode , KeyEvent event)
    {
        if (keyCode == KeyEvent.KEYCODE_BACK)
        {
            if (rgs.getCheckedRadioButtonId() != rgs.getChildAt(0).getId())
            {
                rgs.check(rgs.getChildAt(0).getId());
                return true;
            }
            if ((System.currentTimeMillis() - exitTime) > 2000)
            {
                Toast.makeText(getApplicationContext(), "再按一次退出程序", Toast.LENGTH_SHORT).show();
                exitTime = System.currentTimeMillis();
                return true;
            }
            else
            {
                B5MAppManager.getInstance().AppExit(HomeActivity.this);
            }
        }
        return super.onKeyDown(keyCode, event);
    }
}
